namespace GemBox.Spreadsheet
{
    using System;

    internal class FunctionFormulaToken : FormulaToken
    {
        private FormulaFunctionInfo function;

        public FunctionFormulaToken(FormulaTokenCode code) : base(code, 3, FormulaTokenType.Function)
        {
        }

        public override byte[] ConvertToBytes()
        {
            byte[] array = base.ConvertToBytes();
            BitConverter.GetBytes(this.function.Code).CopyTo(array, 1);
            return array;
        }

        public override void DelayInitialize(object[] data)
        {
            this.function = FormulaFunctionsTable.Instance[data[0] as string];
        }

        public override void Read(byte[] rpnBytes, int startIndex)
        {
            ushort num = BitConverter.ToUInt16(rpnBytes, startIndex);
            this.function = FormulaFunctionsTable.Instance[num];
        }

        public override string ToString()
        {
            return this.function.Name.ToUpper();
        }

        public byte ArgumentsCount
        {
            get
            {
                return this.function.ArgumentsCount;
            }
        }

        public FormulaFunctionInfo Function
        {
            get
            {
                return this.function;
            }
        }
    }
}
